package com.sigmatrix.h5.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.sigmatrix.h5.dao.DisAcctRoleDao;
import com.sigmatrix.h5.dao.DisRoleResDao;
import com.sigmatrix.h5.dao.DisSysResDao;
import com.sigmatrix.h5.entity.DisRoleRes;
import com.sigmatrix.h5.utils.CommonUtils;
import com.sigmatrix.sc.jdbc.common.dao.DaoImpl;
import com.sigmatrix.sc.jdbc.common.lang.Session;
import com.sigmatrix.sc.jdbc.common.lang.User;

/**
 * 
 *@ClassName: DisRoleResDaoImpl
 *@Description: 角色权限表
 *@author MH
 *@date 2017年12月8日 下午1:27:15
 */
@Repository
public class DisRoleResDaoImpl extends DaoImpl<DisRoleRes,Integer> implements DisRoleResDao{
	@Autowired
	private DisAcctRoleDao disAcctRoleDao;
	@Autowired
	private DisSysResDao disSysResDao;
	
	@Override
	public DisRoleRes checkPermission(Integer userId,String eseCode,String moduleCode) {
		User user = new User();
		user.setTablePreffix(eseCode);
		Session.set(user);
		StringBuffer sb = new StringBuffer();
		sb.append("select b.* from ");
		sb.append(disAcctRoleDao.tableName()).append(" a,");
		sb.append(tableName()).append(" b,");
		sb.append(disSysResDao.tableName()).append(" c ");
		sb.append("where a._role_id = b._account_role_id and b._resource_id = c._id ");
		sb.append("and a._account_id = ? ");
		sb.append("and c._code = ?");
		List<DisRoleRes> list = query(sb.toString(), new DefaultRowMapper(), userId,moduleCode);
		Session.clear();
		return CommonUtils.isEmpty(list)?null:list.get(0);
	}
}
